﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Permision.DAL;
using Tools;

namespace Permision.BLL
{
    /// <summary>
    /// Summary description for ActionsRolesBase
    /// </summary>
    public class Per_ModulesManagerBase
    {
        public Per_ModulesManagerBase()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public void InsertUpdate(Per_ModulesEntity item)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", item.Id));
            ls.Add(new SqlParameter("@ModuleName", item.ModuleName));
            SqlParameter[] sqlparam = ls.ToArray();
            Tools.SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_InsertUpdatePer_Modules", sqlparam);
        }
        public void InsertUpdate(string Id, string ModuleName)  
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            ls.Add(new SqlParameter("@ModuleName", ModuleName));
            SqlParameter[] sqlparam = ls.ToArray();
            Tools.SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_InsertUpdatePer_Modules", sqlparam);
        }
        public void Delete(string Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            Tools.SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_DeletePer_Modules", sqlparam);
        }
        public Per_ModulesEntity GetPer_ModulesEntity(DataRow dr)
        {
            Per_ModulesEntity item = new Per_ModulesEntity();            
            item.Id = dr["Id"].ToString();              
            item.ModuleName = dr["ModuleName"].ToString();              
            return item;
        }
        
        public DataTable SelectOneRDT(string Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            return Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_Modules", sqlparam);
        }
        public Per_ModulesEntity SelectOne(string Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_Modules", sqlparam);
            if(dt!=null && dt.Rows.Count>0)
                return GetPer_ModulesEntity(dt.Rows[0]);
            return null;
        }
        public DataTable SelectAllRDT()
        {
            return Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_ModulesAll", null);
        }
        public List<Per_ModulesEntity> SelectAll()
        {
            List<Per_ModulesEntity> lsresult= new List<Per_ModulesEntity>();
            DataTable dt =  Tools.SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "per_SelectPer_ModulesAll", null);
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetPer_ModulesEntity(dt.Rows[i]));            
            return lsresult;
        }
    }
}

